/* eslint-disable */
// @ts-ignore
import { queryOptions, useMutation } from '@tanstack/vue-query';
import type { DefaultError } from '@tanstack/vue-query';
import request from '@/utils/request';
import { CustomRequestOptions } from '@/interceptors/request';

import * as apis from './common';
import * as API from './types';

/** 获取OSS配置 GET /common/oss */
export function commonGetQueryOptions(options: {
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.commonGet(queryKey[1] as typeof options);
    },
    queryKey: ['commonGet', options],
  });
}

/** 获取产品小程序码 POST /common/wei_xin_code */
export function useCommonWeiXinCodeMutation(options?: {
  onSuccess?: (value?: API.ResponseModelUnlimitedCodeModel_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.commonWeiXinCode,
    onSuccess(data: API.ResponseModelUnlimitedCodeModel_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 微信快捷登录 POST /common/wei_xin_login */
export function useCommonWeiXinLoginMutation(options?: {
  onSuccess?: (value?: API.ResponseModelUserCenterLoginModel_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.commonWeiXinLogin,
    onSuccess(data: API.ResponseModelUserCenterLoginModel_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 微信分享签名 POST /common/wei_xin_sign */
export function useCommonWeiXinSignMutation(options?: {
  onSuccess?: (value?: API.ResponseModelWeiXinSignModel_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.commonWeiXinSign,
    onSuccess(data: API.ResponseModelWeiXinSignModel_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}
